package com.example.diagnose.Controller;

import com.example.diagnose.Config.CommonResponse;
import com.example.diagnose.Domain.Article;
import com.example.diagnose.Domain.User;
import com.example.diagnose.Service.ArticleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/article")
@Tag(name = "文章模块")
public class ArticleController {
    @Resource
    ArticleService articleService;

    @Operation(summary = "获取文章信息")
    @GetMapping
    public CommonResponse<List<Article>> getArticle() {
        List<Article> articleList= articleService.getArticle();
        return CommonResponse.BackForSuccess("获得文章信息成功", articleList, "http://127.0.0.1:8081/article");
    }

    @Operation(summary = "获取特定文章信息")
    @GetMapping("/{article_id}")
    public CommonResponse<Article> getArticleById(@PathVariable("article_id") int article_id) {
        Article article= articleService.getArticleById(article_id);
        if(article == null){
            return CommonResponse.BackForError("获得文章信息失败");
        }else {
            return CommonResponse.BackForSuccess("获得文章信息成功", article);
        }
    }

}

